@extends('admin.layout')
@section('title',$title)
@section('content')
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                商品管理
                <small>商品管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 后台页面</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="active">商品添加</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <!-- left column -->
                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">商品添加</h3>
                        </div><!-- /.box-header -->
                        <!-- form start -->
                        @if(session('error'))
                            {{session('error')}}
                        @endif
                        <form role="form" action="/admin/goods/insert" method="post" enctype="multipart/form-data">
                            {{csrf_field()}}
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="exampleInputEmail1">商品名称</label>
                                    <input type="text" name="goodsname" class="form-control" id="exampleInputEmail1" value="{{old('goodsname')}}"
                                           placeholder="请填写商品名称">
                                            @if(!empty($errors->first('goodsname')))
                                                <div class="alert alert-danger alert-dismissable">
                                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                                    <h4><i class="icon fa fa-ban"></i> 注意!</h4>
                                                    <p>{{ $errors->first('goodsname') }}</p>
                                                </div>   
                                            @endif
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">商品描述</label>
                                    <input type="text" name="description" class="form-control" id="exampleInputPassword1" value="{{old('description')}}"
                                           placeholder="请填写商品描述">
                                            @if(!empty($errors->first('description')))
                                                <div class="alert alert-danger alert-dismissable">
                                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                                    <h4><i class="icon fa fa-ban"></i> 注意!</h4>
                                                    <p>{{ $errors->first('description') }}</p>
                                                </div>
                                            @endif

                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">商品价格</label>
                                    <input type="text" name="value" class="form-control" id="exampleInputPassword1" value="{{old('value')}}"
                                           placeholder="请填写商品价格">
                                        @if(!empty($errors->first('value')))
                                           <div class="alert alert-danger alert-dismissable">
                                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                                    <h4><i class="icon fa fa-ban"></i> 注意!</h4>
                                                    <p>{{ $errors->first('value') }}</p>
                                            </div>
                                        @endif
                                </div>
                                <div class="form-group">
                                    <label>商品种类</label>
                                    <select name="cid" class="form-control"  onchange = "return get_shop()">
                                        <option  selected="selected" disabled >请选择</option>
                                    @foreach($data as $v)
                                        <option value="{{$v->id}}" >{{$v -> name}}</option>
                                    @endforeach   
                                    </select>
                                    @if(!empty($errors->first('cid')))
                                           <div class="alert alert-danger alert-dismissable">
                                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                                    <h4><i class="icon fa fa-ban"></i> 注意!</h4>
                                                    <p>{{ $errors->first('cid') }}</p>
                                            </div>
                                    @endif
                                </div>
                                <div class="abc1"></div>
                                <div class="abc"></div>
                                <script type="text/javascript">
                                //根据cid选出它所包含的属性有那几个
                                function function1(attrname)
                                {
                                    

                                    $.ajaxSetup({
                                    headers: {
                                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                                    }
                                   });

                                    // alert(attrname);
                                    // return flase;
                                    $.ajax({
                                        type:'POST',
                                        url:'/admin/goods/check2',
                                        data:'attrname='+attrname,
                                        success:function(data)
                                        {
                                            
                                            var count = data.length;
                                            var i = 0;
                                            var b ='';
                                            b+= "<div class="+data[i].name+">"+attrname+":<select name="+attrname+" width="+300+">";
                                            for(i=0;i<count;i++){
                                                // alert(data[i].name);
                                                b+="<option>"+data[i].name+"</option>";
                                            }
                                            b+="</select></div>";


                                            $('.abc').append(b);
                                            
                                            // console.log(b);
                                            // return b;
                                        },
                                        dataType:'json'
                                    });
                                }

                                function get_shop()
                                {
                                    $('.abc').html('');
                                    $.ajaxSetup({
                                    headers: {
                                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                                    }
                                   });

                                    // alert(1111);
                                    var id = $("select[name='cid']").val();

                                    $.ajax({
                                        type:'POST',
                                        url:'/admin/goods/check3',
                                        data:'id='+id,
                                        success:function(data)
                                        {   
                                            // console.log(data);
                                            
                                            var count = data.length;
                                            var i = 0;
                                            var b ="类目:<select name=type>";
                                            for(i=0;i<count;i++){
                                                b+= "<option value="+data[i].id+">"+data[i].name+"</option>"
                                            }
                                            b+="</select>";
                                            $('.abc1').html(b);
                                        },
                                        dataType:'json'
                                    });  




                                    // alert(id);
                                    $.ajax({
                                        type:'POST',
                                        url:'/admin/goods/check',
                                        data:'id='+id,
                                        success:function(data)
                                        {
                                            // console.log(data);
                                            // $("select[name='type1']").empty();

                                            var count = data.length;
                                            var i = 0;
                                        
                                            for(i=0;i<count;i++){
                                                // alert(data[i].name)
                                                // b+="<div class="+data[i].name+">"+data[i].name+":<select>"+function1(data[1].name)+"</select></div>";
                                                function1(data[i].name);
                                            }
                                            // $(".abc").html(b);
                                            // $('.abc .div'+ +'');
                                        },
                                        dataType:'json'
                                    });
                                    // console.log(data)
                                }


                                </script>





                                 <!-- <div class="form-group">
                                    <label>商品属性qqqqqq</label>
                                    <select name="type1" onchange = "return get_shop1()" class="form-control" >
                                        <option>请选择</option>
                                    </select>
                                </div> -->
                              <!--   <script type="text/javascript">
                                function get_shop1()
                                {
                                    $.ajaxSetup({
                                    headers: {
                                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                                    }
                                   });

                                    // alert(1111);
                                    var  id = $("select[name='type1']").val();
                                    // alert(id);
                                   
                                    $.ajax({
                                        type:'POST',
                                        url:'/admin/goods/check1',
                                        data:'id='+id,
                                        success:function(data)
                                        {
                                            // dd(data);
                                            // alert(data);return false;
                                            $("select[name='type2']").empty();
                                            var count = data.length;
                                            var i = 0;
                                            var b ='';
                                            b+= "<option>请选择</option>";
                                            for(i=0;i<count;i++){
                                                b+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
                                            }
                                            $("select[name='type2']").append(b);
                                        },
                                        dataType:'json'
                                    });
                                }

                                </script> -->
                                <!-- <div class="form-group">
                                    <label>商品属性详情</label>
                                    <select name="type2"  class="form-control">
                                        <option>请选择</option>                                    
                                    </select>
                                </div>
 -->
                                <div class="form-group">
                                    <label for="exampleInputPassword1">所属店铺</label>
                                    <input type="text" name="isshop" class="form-control" id="exampleInputPassword1" value="{{old('isshop')}}"
                                           placeholder="请填写商品所属店铺">
                                        @if(!empty($errors->first('isshop')))
                                           <div class="alert alert-danger alert-dismissable">
                                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                                    <h4><i class="icon fa fa-ban"></i> 注意!</h4>
                                                    <p>{{ $errors->first('isshop') }}</p>
                                            </div>
                                        @endif
                                </div>
                           
                                <div class="form-group">
                                    <label for="exampleInputPassword1">商品库存</label>
                                    <input type="text" name="inventory" class="form-control" id="exampleInputPassword1" value="{{old('inventory')}}"
                                           placeholder="请填写商品库存">
                                        @if(!empty($errors->first('inventory')))
                                           <div class="alert alert-danger alert-dismissable">
                                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                                    <h4><i class="icon fa fa-ban"></i> 注意!</h4>
                                                    <p>{{ $errors->first('inventory') }}</p>
                                            </div>
                                        @endif
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputFile">商品LOGO</label>
                                    <input type="file" name="logo" id="exampleInputFile">
                                    @if(!empty($errors->first('logo')))
                                           <div class="alert alert-danger alert-dismissable">
                                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                                    <h4><i class="icon fa fa-ban"></i> 注意!</h4>
                                                    <p>{{ $errors->first('logo') }}</p>
                                            </div>
                                    @endif
                                    <p class="help-block">请选择一张 120px80px 1M以内的图片 </p>
                                </div>
                                
                            </div><!-- /.box-body -->

                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">提交</button>
                                <button type="reset" class="btn btn-primary">重置</button>
                            </div>
                        </form>
                    </div><!-- /.box -->

                    
                </div><!--/.col (left) -->
                <!-- right column -->
                
            </div>   <!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
@endsection